
coos.xml = function(){};
coos.xml.create = function (str)
{
	if(typeof DOMParser !== "undefined")
	{
		return (new DOMParser()).parseFromString(str, "application/xml");
	}
	else if(typeof ActiveXObject != "undefined")
	{
		if(typeof arguments.callee.activeXString !== "string")
	    {
	    	var versions = ["MSXML2.DOMDocument.6.0",
	         "MSXML2.DOMDocument.5.0",
	         "MSXML2.DOMDocument.4.0",
	         "MSXML2.DOMDocument.3.0",
	         "MSXML2.DOMDocument",
	         "Microsoft.XMLDOM"];
			for(var i=0,len=versions.length; i < len; i++)
			{
				try
				{
					var xml = new ActiveXObject(versions[i]);
					arguments.callee.activeXString = versions[i];
					xml = null;
				}
				catch (e){}
			}
	     }
	     xml = new ActiveXObject(arguments.callee.activeXString);
	     xml.async = "false";
	     xml.loadXML(str);
	     return xml;
   }
};
coos.xml.parse = function (xmlContent){
	var xml = null;
	try
	{
		xml = new DOMParser();
		return xml.parseFromString(xmlContent,"text/xml");;
	}
	catch(e)
	{
		xml = new ActiveXObject("Microsoft.XMLDOM");
		xml.async = false;
		xml.loadXML(xmlContent);
		return xml;
	}
};
coos.xml.root = function (xml)
{
	if (xml == null){return null;}
	return xml.documentElement;
};
coos.xml.format = function(obj)
{
	if(obj == null || typeof(obj) == "undefined"){return null;}
	if(typeof(obj.documentElement) == "object"){
		obj = obj.documentElement;
	}
	return obj;
};
coos.xml.nodes = function(obj,nodeName)
{
	var node = coos.xml.format(obj);
	if(node == null){return null;}
	return node.getElementsByTagName(nodeName);
};
coos.xml.node = function(obj,nodeName)
{
	var node = coos.xml.format(obj);
	if(node == null){return null;}
	return node.getElementsByTagName(nodeName)[0];
};
coos.xml.node.value = function(obj,nodeName)
{
	var node = coos.xml.format(obj);
	if(node == null){return "";}
	var element = node.getElementsByTagName(nodeName);
	var value = "";
	if(element[0].firstChild != null)
	{
		value = element[0].firstChild.nodeValue;
	}
	return value;
};
coos.xml.node.values = function(obj,nodeName)
{
	var node = coos.xml.format(obj);
	if(node == null){return null;}
	var nodes = node.getElementsByTagName(nodeName);
	var len = nodes.length;
	var values = [];
	for(var i = 0; i < len; i++){
		if(nodes[i].firstChild != null)
		{
			values.push(nodes[i].firstChild.nodeValue);
		}else{
			values.push("");
		}
	}
	return values;
};
coos.xml.childNodes = function(obj)
{
	var node = coos.xml.format(obj);
	if(node == null){return null;}
	var temp = [];
	var nodes = node.childNodes;
	for(var i = 0; i < nodes.length; i++)
	{
		if(nodes[i].nodeType == 1)
		{
			temp.push(nodes[i]);
		}
	}
	return temp;
};
coos.xml.attribute = function(){};
coos.xml.attribute.value = function(obj,attributeName)
{
	var node = coos.xml.format(obj);
	if(node == null){return "";}
	return node.getAttribute(attributeName);
};
coos.xml.attribute.values = function(nodes,nodeName,attributeName)
{
	if(typeof(nodes.length) == "undefined"){
		nodes = coos.xml.childNodes(nodes);
	}
	var len = nodes.length;
	var values = [];
	for(var i = 0; i < len; i++)
	{
		if(nodes[i].nodeName == nodeName && nodes[i].getAttribute(attributeName) != null)
		{
			values.push(nodes[i].getAttribute(attributeName));
		}
	}
	return values;
};
coos.xml.clear = function(obj)
{
	obj = null;
};
